import type { INpcData } from '../../data/NpcData';
import type {
  RemoteData,
  // NpcInfo,
  // ClientEvents,
  // RemoteType,
} from '../../../../../shares/sharesApp';
import { RemoteMgr } from '../../mgr/RemoteMgr';

export class Npc {
  /**
   * NPC的唯一标识
   */
  private id: string = '';
  /**
   * 客户端事件名称
   */
  private clientEvent: string = '';
  /**
   * NPC实体
   */
  private entity?: GameEntity;
  /**
   * 新建NPC实例
   */
  constructor() {}

  public start(config: INpcData): void {
    this.id = config.id;
    this.clientEvent = config.clientEvent;
    console.log(`(Server) Npc ${this.id} start`);
    const entity = config.entity || world.querySelector(`#${this.id}`);
    if (entity) {
      this.entity = entity;
      entity.interactColor.copy(new GameRGBColor(255, 255, 255));
      entity.interactHint = config.interactHint;
      entity.interactRadius = 3;
      // entity.interactSound;
      entity.enableInteract = true;
    }
    this.bindInteractEvents();
  }

  private bindInteractEvents(): void {
    const npc = this.entity || world.querySelector(`#${this.id}`)!;
    npc.onInteract(({ entity }) => {
      // RemoteMgr.instance.send<NpcInfo>(entity, {
      //     type: this.clientEvent as RemoteType,
      //     data: null,
      // });
    });
  }
}
